﻿using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Drive.LiveExcelHost
{
    public class RedisUserStore
    {

        public static async Task<string> GetNickNameAsync(string uid)
        {
            var redis = ConnectionMultiplexer.Connect(RedisConf.connectionString);
            var db = redis.GetDatabase(0);
            return await db.HashGetAsync("NickName", uid);
        }

        public static async Task<bool> SetNickNameAsync(string uid, string nickName)
        {
            var redis = ConnectionMultiplexer.Connect(RedisConf.connectionString);
            var db = redis.GetDatabase(0);
            return await db.HashSetAsync("NickName", uid, nickName, when: When.NotExists);
        }
        public static string GetNickName(long uid)
        {
            var redis = ConnectionMultiplexer.Connect(RedisConf.connectionString);
            var db = redis.GetDatabase(0);
            return db.HashGet("NickName", uid);
        }

        public static void SetNickName(long uid, string nickName)
        {
            var redis = ConnectionMultiplexer.Connect(RedisConf.connectionString);
            var db = redis.GetDatabase(0);
            db.HashSet("NickName", nickName, uid, when: When.NotExists);
            db.HashSet("NickName", uid, nickName);
        }

        public static string GetUserIdByNickName(string nickName)
        {
            var redis = ConnectionMultiplexer.Connect(RedisConf.connectionString);
            var db = redis.GetDatabase(0);
            return db.HashGet("NickName", nickName);
        }
    }
}
